<template>
	<view class="content">
		<view class="nav-box flexWrap">
			<view class="nav-item flexWarpCenterColumn" :class="{active:currmentIndex==1}" @tap="changeNav(1)">
				<text>进行中</text>
				<text class="nav-line"></text>
			</view>
			<view class="nav-item flexWarpCenterColumn" :class="{active:currmentIndex==0}" @tap="changeNav(0)">
				<text>未开始</text>
				<text class="nav-line"></text>
			</view>
			<view class="nav-item flexWarpCenterColumn" :class="{active:currmentIndex==2}" @tap="changeNav(2)">
				<text>已结束</text>
				<text class="nav-line"></text>
			</view>
		</view>
		<view class="task-list">
			<view class="empty-box" v-if="taskList.length==0">
				<image src="https://static.mo-yu.vip/wechat/images/orderEmpty.png" class="empty-image"></image>
			</view>
			<view class="task-item" v-for="(item,index) in taskList" :key="index">
				<view class="task-top flexWrap">
					<view class="task-name">[{{item.task_name}}]</view>
					<view class="btn-box flexWrapNo">
						<view @tap="taskDel(index,item.id)">删除</view>
						<view @tap="goPage('/pages/manage/editTask?taskId='+item.id)">编辑</view>
					</view>
				</view>
				<view class="task-cont">{{item.task_desc}}</view>
				<view class="task-bottom">
					<view class="task-data flexWrap">
						<view class="data-item flexWarpCenterColumn" @tap="goPage('/pages/manage/challengeSuccessList?taskId='+item.id)">
							<text>{{item.finish_num}}</text>
							<text class="data-text">挑战成功</text>
						</view>
						<view class="data-item flexWarpCenterColumn">
							<text>{{item.join_num}}</text>
							<text class="data-text">参与挑战</text>
						</view>
						<view class="data-item flexWarpCenterColumn">
							<text>{{item.remaining_quantity}}</text>
							<text class="data-text">关联优惠券剩余</text>
						</view>
					</view>
					<view class="time-box">
						任务周期:{{item.start_date}}～{{item.end_date}}
					</view>
				</view>
			</view>
		</view>
		<view class="add-btn" @tap="goPage('/pages/manage/editTask')">+ 新建任务挑战</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currmentIndex:1,
				taskList:[]
			};
		},
		onShow() {
			this.getTasklist();
		},
		methods:{
			changeNav(index){
				this.currmentIndex=index
				this.getTasklist()
			},
			// 获取优惠券列表
			getTasklist(){
				this.$request.post(this.$api.taskList, {
					store_id:uni.getStorageSync('store_id'),
					status:this.currmentIndex
				}, {
					token:true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code==1) {
						this.taskList=data
						console.log(this.taskList)
					}
				})
			},
			taskDel(index,id){
				this.$request.post(this.$api.taskDel, {
					store_id:uni.getStorageSync('store_id'),
					task_id:id
				}, {
					token:true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code==1) {
						this.$tools.showToast('删除成功');
						this.taskList.splice(index,1)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		padding-bottom: 120upx;
	}
	.empty-box{
		margin: 64upx auto;
		width: 476upx;
		height: 280upx;
	}
	.content{
		padding: 36upx;
	}
	.nav-box{
		padding: 20upx 74upx;
		border-bottom: 1rpx solid #36355E;
		.nav-item{
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #82819B;
			.nav-line{
				width: 86rpx;
				height: 4rpx;
				margin-top: 10upx;
			}
		}
		.active{
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			.nav-line{
				background: #26BCFD;
			}
		}
	}
	.task-list{
		margin-top: 58upx;
		.task-item{
			margin-bottom: 32upx;
			.task-top{
				.task-name{
					font-size: 32rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFB726;
					line-height: 36rpx;
				}
				.btn-box{
					view{
						width: 112rpx;
						height: 44rpx;
						text-align: center;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						opacity: 1;
						border: 2rpx solid #FFFFFF;
						font-size: 20rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						line-height: 44rpx;
						margin-left: 20upx;
					}
				}
			}
			.task-cont{
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 36rpx;
				margin-top: 22rpx;
			}
			.task-bottom{
				margin-top: 20upx;
				.task-data{
					height: 160rpx;
					background: #1D1C5C;
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					padding: 0 30upx;
					.data-item{
						font-size: 36rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #FFFFFF;
						.data-text{
							font-size: 24rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #8E8EAE;
						}
					}
				}
				.time-box{
					height: 78rpx;
					background: #1D1C5C;
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 78rpx;
					margin-top: 2upx;
					padding: 0 28upx;
				}
			}
		}
	}
	.add-btn{
		height: 120rpx;
		background: #1D1C5C;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 120rpx;
		text-align: center;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		margin: auto;
	}
</style>
